'''
目标函数：
    min max{x1-x2+x3,x1+x2,x1-x3}
约束条件：
    x1+x2-x3=1
    2*x1-x2=2
    x1-2*x2+x3<=1
    x1,x2,x3>=0

这类问题的解法是令x0=max{x1-x2+x3,x1+x2,x1-x3}
即x0>=x1-x2+x3 x0>=x1+x2 x0>=x1-x3
转化为：
    min x0
    x1+x2-x3=1
    2*x1-x2=2
    x1-2*x2+x3<=1
    -x0+x1-x2+x3<=0
    -x0+x1+x2<=0
    -x0+x1-x3<=0
    x1,x2,x3>=0
'''
import numpy as np
from scipy.optimize import linprog

c = np.array([1, 0, 0, 0])
A_ub = np.array([[0, 1, -2, 1], [-1, 1, -1, 1], [-1, 1, 1, 0], [-1, 1, 0, -1]])
b_ub = np.array([1, 0, 0, 0])
A_eq = np.array([[0, 1, 1, -1], [0, 2, -1, 0], ])
b_eq = np.array([1, 2])
bounds = (0, None)
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=(bounds, bounds, bounds, bounds))
print(res)
'''
     fun: 1.0
 message: 'Optimization terminated successfully.'
     nit: 3
   slack: array([0., 0., 0., 0.])
  status: 0
 success: True
       x: array([1., 1., 0., 0.])
'''
